﻿<div ms-controller="CPGLLIST">
    <!-- 添加按钮 -->
    <div class="btn-add">
        <button type="button" class="btn btn-info btn-lg" ms-click="AddView('CRM_CPGL')"><i class="iconfont icon-jiahao ft12 mr5"></i>添加产品</button>
        <a class="btn btn-info btn-lg" ms-click="dcCP()"><i class="iconfont icon-dc  ft12 mr5"></i>导出</a>
    </div>
    <!-- 按条件选择 -->
    <div class="tab-filter-type">
       
        <div class="oh">
            <h5 class="pull-left tr">产品类型：</h5>
            <ul class="tab-type ft14">
                <li ms-click="SelectXJType('')"><span class="active">全部</span></li>
                <li ms-repeat-el="TypeData" ms-click="SelectXJType(el.ID)"><span>{{el.TypeName}}</span></li>
            </ul>
        </div>

        <!-- 搜索 -->
        <div class="oh mr20 mt20">
            <div class="input-group ml15" style="width: 295px; float: left">
                <input type="search" class="form-control" ms-duplex="search.searchcontent" placeholder="请输入产品名称">
                <span class="input-group-addon" ms-click="GetLIST()">搜索</span>
            </div>
            <button type="button" class="btn btn-info pull-right mt5" data-toggle="modal" data-target="#myselfModal">自定义显示</button>
        </div>
    </div>
    <!-- 展开更多选项 -->
    <div class="add-tab ft14 tc mt20" style="display:none;">
        <span>更多筛选<i class="caret"></i></span>
    </div>
    <!-- 表格 -->
    <div class="default-tab ft14 pt20 table-responsive hover-btn">
        <table class="table table-striped table-responsive table-hover">
            <thead>
                <tr>
                    <th class="tc">
                 
                        序号
                    </th>
                    <th ms-repeat-im="ShowColumns" ms-visible="im.IsSel">{{im.ColText}}</th>
                    <th style="width:80px;">
                    </th>
                </tr>
            </thead>
            <tbody>
                <tr ms-repeat-el="tmpListData" >
                    <td class="tc">
                     
                        {{$index+1+page.pagecount*(page.pageindex-1)}}
                    </td>
                    <td ms-repeat-im="ShowColumns" ms-click="ViewFormNew('CRM_CPGL',el.ID,'',$event)" ms-class-1="lk:im.type=='link'" style="min-width:120px;" ms-visible="im.IsSel">{{FnFormat(el[im.ColName],im)|html}}</td>
                    <td style="min-width:100px;">
                        <span class="btn-click">
                            <a class="cz-btn ft18 bj-color tip" data-toggle="tooltip" title="编辑" ms-if="el.CRUser==userName" ms-click="EditForm('CRM_CPGL',el.ID,'',$event)">
                                <i class="iconfont icon-bianji"></i>
                            </a>
                            <a class="cz-btn ft18 sc-color tip" data-toggle="tooltip" title="删除" ms-if="el.CRUser==userName" ms-click="DELCP(el,$event)">
                                <i class="iconfont icon-shanchu"></i>
                            </a>
                        </span>
                    </td>
                </tr>

            </tbody>
            <tfoot>
                <tr ms-if="isnull"><td class="tc"></td><td>暂无数据</td></tr>
            </tfoot>
        </table>
    </div>
    <div class="ui-datatable-page ft14 pl20">

        <div id="pageDiv" ms-visible="model.page.total>model.pageNum[0].num" class="pull-right"></div>
        <div class="pull-right" ms-visible="tmpListData.size()!=0">
            <span>共{{model.page.total}}条记录</span>
            <span ms-visible="model.page.total>model.pageNum[0].num">
                选择每页条数
                <select style="height: 25px; width: 50px;" ms-change="selNum(this.value)" ms-duplex="model.page.pagecount">
                    <option ms-repeat-pg="pageNum" ms-attr-value="pg.num" ms-attr-selected="pg.num==model.page.pagecount?'selected':''">{{pg.num}}</option>
                </select>
            </span>
        </div>

    </div>
</div>

<script>

    var tempindex = avalon.define({
        $id: "CPGLLIST",
        curXJType: "",
        tmpListData:[],
        SelectType: function (type) {
            model.search.seartype = type;
            tempindex.GetLIST();
        },
        SelectXJType: function (type) {
            tempindex.curXJType = type;
            tempindex.GetLIST();
        },
        selNum: function (item) {    //选择显示的条数
            model.page.pagecount = item;
            tempindex.GetLIST();
        },
        InitWigetData: function () {

            //显示的列名
            model.ShowColumns.clear();
            model.ShowColumns.pushArray([
                { "ColName": "Name", "ColText": "产品名称", "IsSel": true, "format": "text", "type": "link" },
                { "ColName": "BianHao", "ColText": "产品编号", "IsSel": true, "format": "text" },
                 { "ColName": "Price", "ColText": "标准单价(元)", "IsSel": true, "format": "text" },
                { "ColName": "DanWei", "ColText": "销售单位", "IsSel": true, "format": "text" },
                { "ColName": "TypeName", "ColText": "产品类型", "IsSel": true, "format": "text" },
                { "ColName": "ChengBen", "ColText": "单位成本(元)", "IsSel": true, "format": "text" }
                //{ "ColName": "PContent", "ColText": "产品介绍", "IsSel": true, "format": "text" }
            ]);
            //类型数据

            model.GetTypeData("15");
            tempindex.GetLIST();
        },
        DELCP: function (item, event) {
            if (event.stopPropagation) {
                event.stopPropagation();
            }
            top.ComFunJS.winconfirm("确认要删除吗", function () {
                $.post('/API/VIEWAPI.ashx?Action=CRM_DELCPBYID', { "P1": item.ID }, function (result) {
                    result = JSON.parse(result)
                    if (result.ErrorMsg == "") {
                        top.ComFunJS.winsuccess("删除成功");
                        tempindex.tmpListData.remove(item);
                    } else {
                        top.ComFunJS.winwarning(result.ErrorMsg);
                    }
                })
            }, function () { })
        },
        GetLIST: function () {
            model.page.pageindex = 1;
            tempindex.tmpListData.clear();
            $.getJSON('/API/VIEWAPI.ashx?Action=CRM_GETCPLIST', { p: 1, P1: model.search.seartype,pagecount:model.page.pagecount, Content: model.search.searchcontent, lb: tempindex.curXJType }, function (resultData) {
                if (resultData.ErrorMsg == "") {
                    tempindex.tmpListData = resultData.Result;
                    model.page.total = resultData.Result1;
                    if (tempindex.tmpListData.size() == 0) { model.isnull = true; } else { model.isnull = false; }
                    laypage({
                        cont: 'pageDiv', //容器。值支持id名、原生dom对象，jquery对象。
                        pages: Math.ceil(parseInt(resultData.Result1) * 1.0 / model.page.pagecount), //通过后台拿到的总页数
                        curr: 1, //初始化当前页
                        skin: 'molv',
                        jump: function (e) { //触发分页后的回调
                            if (e.curr != model.page.pageindex) {
                                $.getJSON('/API/VIEWAPI.ashx?Action=CRM_GETCPLIST', { p: e.curr, P1: model.search.seartype, pagecount: model.page.pagecount, Content: model.search.searchcontent, lb: tempindex.curXJType }, function (resultData) {
                                    if (resultData.ErrorMsg == "") {
                                        tempindex.tmpListData = resultData.Result;
                                    }
                                })
                                model.page.pageindex = e.curr;
                            }
                        }
                    });
                }
            })
        },
        dcCP: function () {
            if (tempindex.tmpListData.size() > 0) {
                $(this).attr("href", '/API/VIEWAPI.ashx?Action=CRM_EXPORTCP&P1=' + model.search.seartype + '&Content=' + model.search.searchcontent + '&lb=' + tempindex.curXJType);
            }
            else {
                top.ComFunJS.winwarning("无数据");
            }
        }
    })
</script>
